//import sun.misc.BASE64Encoder; // java8
import java.util.Base64;       // java17

public class Base64EncodingExample {
    public static void main(String[] args) {
        String textToEncode = "Hello, World!";
        String encoded = Base64.getEncoder().encodeToString(textToEncode.getBytes());
        System.out.println("Encoded: " + encoded);
        String decoded = new String(Base64.getDecoder().decode(encoded));
        System.out.println("Decoded: " + decoded);
    }
}